//
//  CQStatusRetweetView.swift
//  weibo
//
//  Created by chengqiang on 16/7/25.
//  Copyright © 2016年 chengqiangBiaodashi. All rights reserved.
//

import UIKit

class CQStatusRetweetView: UIView {

    var retweetStatus :CQstatus?{
        didSet{
            
            
            //拿到被转发微博的模型
            if retweetStatus == nil{
                retweentContentLable.text = "没有被转发微博"
            }else{
//                let name = retweetStatus?.user?.screen_name ?? "没有名称"
//                let text = retweetStatus?.text ?? "没有微博内容"
//                let content = "@\(name):\(text)"
                retweentContentLable.text=retweetStatus?.reteeeText
            }
            
            //设置配图图片
            retweetPictureView.imageUrl = retweetStatus?.storepicutureURLs
            
            retweetPictureView.snp_updateConstraints { (make) in
                var margin:CGFloat = 0
                if retweetStatus?.storepicutureURLs != nil && retweetStatus?.storepicutureURLs?.count>0{
                    margin=CellMargin
                }
                make.top.equalTo(retweentContentLable.snp_bottom).offset(margin)
            }
        }
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.whiteColor()
        setupUI()
    }
    
    
    private func setupUI(){
        
        self.addSubview(retweentContentLable)
        self.addSubview(retweetPictureView)
        
        
        retweentContentLable.snp_makeConstraints { (make) in
            make.leading.top.equalTo(self).offset(CellMargin)
        }
        retweetPictureView.snp_makeConstraints { (make) in
            make.leading.equalTo(self).offset(CellMargin)
            make.top.equalTo(retweentContentLable.snp_bottom).offset(CellMargin)
            make.size.equalTo(CGSize(width: 300, height: 300))
        }
        self.snp_makeConstraints { (make) in
            make.bottom.equalTo(retweetPictureView).offset(CellMargin)
        }
        
        
    }
    
    
//被转发的微博
    private lazy var retweentContentLable:UILabel = {
        let lable = UILabel(textColor: UIColor.darkGrayColor(),fontSize: CellFontSize)
        
        lable.preferredMaxLayoutWidth = UIScreen.width()-2*CellMargin
        lable.numberOfLines = 0
        return lable
    }()
//被转发微博的视图
    private lazy var retweetPictureView :CQStatusPictureView = CQStatusPictureView()
}
